//
//  XHTabBarController.m
//  xinhua
//
//  Created by fengyn on 15/10/26.
//  Copyright © 2015年 lexingsoft. All rights reserved.
//

#import "XHTabBarController.h"

//#import "XHOwnViewController.h"
//#import "XHFirstViewController.h"
//#import "XHDiscoverViewController.h"
//#import "XHOrderViewController.h"


#import "Services.h"

@interface XHTabBarController ()<UITabBarControllerDelegate>
@property (nonatomic, strong) UIButton *centerButton;
@property (nonatomic, strong) UIView *ui_blueView;
@end

@implementation XHTabBarController

- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.delegate=self;
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
    
//    XHFirstViewController *viewController1=[[XHFirstViewController alloc] init];
//    XHOrderViewController *viewController2=[[XHOrderViewController alloc] init];
//    XHDiscoverViewController *viewController3=[[XHDiscoverViewController alloc] init];
//    XHOwnViewController *viewController4=[[XHOwnViewController alloc] init];
//    
//    viewController1.title=@"first";
//    viewController2.title=@"order";
//    viewController3.title=@"discover";
//    viewController4.title=@"user";
//    
//    UINavigationController *nav1=[[UINavigationController alloc] initWithRootViewController:viewController1];
//    UINavigationController *nav2=[[UINavigationController alloc] initWithRootViewController:viewController2];
//    UINavigationController *nav3=[[UINavigationController alloc] initWithRootViewController:viewController3];
//    UINavigationController *nav4=[[UINavigationController alloc] initWithRootViewController:viewController4];
//    
//    self.viewControllers=@[nav1,nav2,nav3,nav4];
//    
//    NSArray *titles = @[@"首页", @"订单", @"发现", @"个人"];
//    NSArray *images = @[@"shouye_icon_shouye2",
//                        @"shouye_icon_faxian2",
//                        @"shouye_icon_dingdan2",
//                        @"shouye_icon_geren2"];
//    NSArray *selectImages = @[@"shouye_icon_shouye1",
//                              @"shouye_icon_faxian1",
//                              @"shouye_icon_dingdan1",
//                              @"shouye_icon_geren1"];
//    
//    [self.tabBar.items enumerateObjectsUsingBlock:^(UITabBarItem *item, NSUInteger idx, BOOL *stop) {
//        [item setTitle:titles[idx]];
//        [item setImage:[[UIImage imageNamed:images[idx]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
//        [item setSelectedImage:[[UIImage imageNamed:selectImages[idx]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
//        [item setTitleTextAttributes:@{NSForegroundColorAttributeName:[ColorManager colorWithHexString:@"#929292"]} forState:UIControlStateNormal];
//        [item setTitleTextAttributes:@{NSForegroundColorAttributeName:[ColorManager colorWithMain]} forState:UIControlStateSelected];
//    }];
//    self.tabBar.translucent=NO;
}

//-(void)addCenterButtonWithImage:(UIImage *)buttonImage
//{
//    _centerButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    
//    CGPoint origin = [self.view convertPoint:self.tabBar.center toView:self.tabBar];
//    CGSize buttonSize = CGSizeMake(self.tabBar.frame.size.width / 5, self.tabBar.frame.size.height + 20);
//    
//    _centerButton.frame = CGRectMake(origin.x - buttonSize.height/2, origin.y - buttonSize.height/2, buttonSize.height, buttonSize.height);
//    
//    [_centerButton setCornerRadius:buttonSize.height/2];
//    [_centerButton setBackgroundColor:[ColorManager colorWithNavigationBarBackground]];
//    [_centerButton setImage:buttonImage forState:UIControlStateNormal];
//    [_centerButton setTitleColor:[ColorManager colorWithHexString:@"#C1A08B"] forState:UIControlStateNormal];
//    _centerButton.titleLabel.font=[UIFont systemFontOfSize:6];
//    [_centerButton setTitle:@" " forState:UIControlStateNormal];
//    
//    CGSize imageSize = _centerButton.imageView.frame.size;
//    CGSize titleSize = _centerButton.titleLabel.frame.size;
//    CGFloat totalHeight = (imageSize.height + titleSize.height + 6);
//    [_centerButton setTitleEdgeInsets:UIEdgeInsetsMake(0.0, - imageSize.width, - (totalHeight - titleSize.height),0.0)];
//    [_centerButton setImageEdgeInsets:UIEdgeInsetsMake(- (totalHeight - imageSize.height), 0.0, 0.0, - titleSize.width)];
//    
//    [_centerButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
//    
//    [self.tabBar addSubview:_centerButton];
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self checkMessage];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)buttonPressed:(id)sender{
}

- (void)checkMessage{
    if ([DataManager sharedInstance].apnsMessage)
    {
//        NSDictionary *apns=[DataManager sharedInstance].apnsMessage[@"aps"];
        [self setSelectedIndex:0];
        UINavigationController *navigationController=self.viewControllers[0];
       //        if ([apns[@"type"] isEqualToString:@"ACTIVITY"]) {
//           
//        }else if([apns[@"type"] isEqualToString:@"INFORMATION"]){
//            
//        }
//        else if([apns[@"type"] isEqualToString:@"COUPON"]){
//            
//        }
//        else if([apns[@"type"] isEqualToString:@"CONTENT"])
//        {
//            
//        }
//        else
//        {
//        }
        [DataManager sharedInstance].apnsMessage=nil;
    }
}

- (void)applicationDidBecomeActive{
    [self checkMessage];
}
///支付成功
- (void)goDivingRoad:(NSString *)type
{
    if([type isEqualToString:@"signUp"])
    {
        //报名完成
    }
    else if([type isEqualToString:@"insurance"])
    {
        //保险购买完成
    }
}

///注册成功之后返回个人中心
- (void)goOwnViewController
{
//    [self setSelectedIndex:3];
//    UINavigationController *navigationController=self.viewControllers[3];
//    XHOwnViewController *viewController=navigationController.viewControllers.firstObject;
//    [viewController.navigationController popToRootViewControllerAnimated:NO];
}



- (void)goMyPreferentialView{

}

- (void)goOrderViewShowTabIndex:(NSUInteger)index{

}

- (void)goMyFoodOrderViewController{
}

- (void)loginAction{
}

- (void)goMyCouponView
{

}

#pragma mark - UITabBarControllerDelegate
//- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
//    self.ui_blueView.hidden=!(self.selectedIndex==1);
//}
//
//- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController NS_AVAILABLE_IOS(3_0)
//{
//    if(viewController==self.viewControllers[2])
//    {
//        if(![[DataManager sharedInstance] isLogin])
//        {
//            [self loginAction];
//            return NO;
//        }
//    }
//    return YES;
//}
@end
